<?php
if(!defined('FOLDER_TEMPLATE')){
    define('FOLDER_TEMPLATE','/template');
}
class Template{
    var $tpl_name;
    var $tpl_css = array();
    var $tpl_js = array();
    var $tpl_type = '';
    var $url_css;
    var $url_js;
    var $url_img;
    function __construct($id = 0){

        if($id){
            $db_query = new db_query('SELECT * FROM template WHERE tpl_id = '.$id.' LIMIT 1');
        }else{

            $db_query = new db_query('SELECT * FROM template WHERE tpl_active = 1 ORDER BY tpl_id LIMIT 1');

        }

        $tpl = mysql_fetch_assoc($db_query->result);unset($db_query);
        $this->tpl_name = $tpl['tpl_name'];
        if($tpl['tpl_css_file']){
            $this->tpl_css = explode('|',$tpl['tpl_css_file']);
        }
        if($tpl['tpl_js_file']){
            $this->tpl_js = explode('|',$tpl['tpl_js_file']);
        }
        $this->url_css = FOLDER_TEMPLATE . '/' . $this->tpl_name . '/themes/css/';
        $this->url_js = FOLDER_TEMPLATE . '/' . $this->tpl_name . '/themes/js/';
        $this->url_img = FOLDER_TEMPLATE . '/' . $this->tpl_name . '/themes/img/';
    }
    function LoadCSS(){
        $str = '';
        foreach($this->tpl_css as $css_file){
            $str .= '<link rel="stylesheet" type="text/css" href="' . $this->url_css . $css_file .'">';
        }
        return $str;
    }
    function LoadJS(){
        $str = '';
        foreach($this->tpl_js as $js_file){
            $str .= '<script type="text/javascript" src="' . $this->url_js . $js_file .'"></script>';
        }
        return $str;
    }
}
?>